<?php
	
	function getAllMember($dsp_home = false){
		$sql = 'SELECT ACCOUNT_ID 
					, ACCOUNT_NAME 
					, ACCOUNT_GROOM_NAME
					, ACCOUNT_BRIDE_NAME
				FROM TB_ACCOUNT 
				WHERE ACCOUNT_TYPE = '.USER_ACCOUNT
				.(($dsp_home) 	? ' ORDER BY ACCOUNT_ID DESC
									LIMIT 0 , 10' 
								: ' ORDER BY ACCOUNT_NAME ');
		$rs = mysql_query($sql) or die(mysql_error());
		$arr_list_member = array();
		while ($arr = mysql_fetch_assoc($rs)){
			$arr_list_member[$arr['ACCOUNT_ID']]['account_name'] = $arr['ACCOUNT_NAME'];
			$arr_list_member[$arr['ACCOUNT_ID']]['account_gr_name'] = $arr['ACCOUNT_GROOM_NAME'];
			$arr_list_member[$arr['ACCOUNT_ID']]['account_br_name'] = $arr['ACCOUNT_BRIDE_NAME'];
			$arr_list_member[$arr['ACCOUNT_ID']]['account_avatar_img'] = getCoupleImage($arr['ACCOUNT_ID']);
		}
		
		return $arr_list_member;
	}
	function displayWeddingDate ( $p_wedding_date ){
		global $arr_day_of_week;
		global $arr_month;

		$day_of_week = $arr_day_of_week[date("D",strtotime($p_wedding_date))];
		$day = date("d",strtotime($p_wedding_date));
		$year = date("Y",strtotime($p_wedding_date));
		$month = date("m",strtotime($p_wedding_date));

		return $day_of_week . ',<span class="date_wd"> '. $day .'/'.$month .'/'.$year.'</span>';
	}

	function isAccountNameExists ( $p_account_name ){
		$sql = 'SELECT ACCOUNT_ID FROM TB_ACCOUNT WHERE ACCOUNT_NAME = "'.$p_account_name.'" ';
		$rs = mysql_query($sql);
		if ( mysql_num_rows($rs) > 0 )
			return true;
		return false;
	}

	function isAccountEmailExists ( $p_account_email ){
		$sql = 'SELECT ACCOUNT_ID FROM TB_ACCOUNT WHERE ACCOUNT_EMAIL = "'.$p_account_email.'" ';
		$rs = mysql_query($sql);
		if ( mysql_num_rows($rs) > 0 )
			return true;
		return false;
	}
	function getCoupleInfo ( $p_account_id ){
		$arr_info = array();
		$sql = 'SELECT ACCOUNT_BRIDE_NAME 
						,ACCOUNT_GROOM_NAME
						,ACCOUNT_WEDDING_DATE
						,ACCOUNT_WEDDING_LOCATION
				FROM TB_ACCOUNT
				WHERE ACCOUNT_ID = '.$p_account_id.'
				';
		$rs = mysql_query($sql) or die ( mysql_error() );
		if ( $arr = mysql_fetch_assoc($rs) ){
			$arr_info['bride_name'] = $arr['ACCOUNT_BRIDE_NAME'];
			$arr_info['groom_name'] = $arr['ACCOUNT_GROOM_NAME'];
			$arr_info['wedding_date'] = $arr['ACCOUNT_WEDDING_DATE'];
			$arr_info['wedding_location'] = $arr['ACCOUNT_WEDDING_LOCATION'];
		}
		return $arr_info;
	}
	function insertAccount(
		$p_account_name
			,$p_account_pass
			,$p_account_email
			,$p_account_bride_name
			,$p_account_groom_name
			,$p_account_wedding_date
			,$p_account_wedding_location
			,$p_account_type
	
	){
		mysql_query("
			INSERT INTO TB_ACCOUNT(
				ACCOUNT_NAME
					,ACCOUNT_PASS
					,ACCOUNT_EMAIL
					,ACCOUNT_BRIDE_NAME
					,ACCOUNT_GROOM_NAME
					,ACCOUNT_WEDDING_DATE
					,ACCOUNT_WEDDING_LOCATION
					,ACCOUNT_TYPE
	
			)VALUES(
				'".$p_account_name."'
					,'".$p_account_pass."'
					,'".$p_account_email."'
					,'".$p_account_bride_name."'
					,'".$p_account_groom_name."'
					,".(($p_account_wedding_date ? "'".$p_account_wedding_date."'" : 'NULL') ) ."
					,'".$p_account_wedding_location."'
					,'".$p_account_type."'
	
			)	
		")or die(mysql_error());
		return mysql_insert_id();
	}
	
	function updateAccount(
		$p_accout_id
			,$p_account_name
			,$p_account_pass
			,$p_account_email
			,$p_account_bride_name
			,$p_account_groom_name
			,$p_account_wedding_date
			,$p_account_wedding_location
			,$p_account_type
	
	){
		mysql_query("
			UPDATE TB_ACCOUNT 
			SET
				ACCOUNT_NAME='".$p_account_name."'
					,ACCOUNT_PASS='".$p_account_pass."'
					,ACCOUNT_EMAIL='".$p_account_email."'
					,ACCOUNT_BRIDE_NAME='".$p_account_bride_name."'
					,ACCOUNT_GROOM_NAME='".$p_account_groom_name."'
					,ACCOUNT_WEDDING_DATE='".$p_account_wedding_date."'
					,ACCOUNT_WEDDING_LOCATION='".$p_account_wedding_location."'
					,ACCOUNT_TYPE='".$p_account_type."'
	
			WHERE ACCOUNT_ID =  '".$p_accout_id."'
		");
	}

	function getAllAccount($p_where_clause,$p_offset,$p_num_row,$p_order_by=" ACCOUNT_ID DESC "){
		$rs = mysql_query("
		SELECT 
			ACCOUNT_ID
				,ACCOUNT_NAME
				,ACCOUNT_PASS
				,ACCOUNT_EMAIL
				,ACCOUNT_BRIDE_NAME
				,ACCOUNT_GROOM_NAME
				,ACCOUNT_WEDDING_DATE
				,ACCOUNT_WEDDING_LOCATION
				,ACCOUNT_TYPE

		FROM TB_ACCOUNT	
		WHERE 1 ".$p_where_clause."		
		ORDER BY ".$p_order_by."
		LIMIT ".$p_offset.",".$p_num_row."
		")or die(mysql_error());
		return $rs;
	}

	function getSingerAccount($p_accout_id){
		$rs = mysql_query("
		SELECT 
			ACCOUNT_ID
				,ACCOUNT_NAME
				,ACCOUNT_PASS
				,ACCOUNT_EMAIL
				,ACCOUNT_BRIDE_NAME
				,ACCOUNT_GROOM_NAME
				,ACCOUNT_WEDDING_DATE
				,ACCOUNT_WEDDING_LOCATION
				,ACCOUNT_TYPE

		FROM TB_ACCOUNT	
		WHERE ACCOUNT_ID =  '".$p_accout_id."'		
		")or die(mysql_error());
		return $rs;
	}